//
//  ViewController.m
//  ProjectSource_Demo
//
//  Created by Liu on 15/11/24.
//  Copyright © 2015年 AngryBear. All rights reserved.
//

#import "ViewController.h"
#import "AlbumViewController.h"
#import "CalendarVC.h"
#import "SettingVC.h"

#import "LXAlertView.h"
#import "UITableViewCell+LXSaparateLine.h"
#import "LXAlertManager.h"
#import "LXNetworkOperation.h"



@interface ViewController ()<UITableViewDataSource, UITableViewDelegate>
@property (strong, nonatomic) IBOutlet UITableView *tableView;

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
    
}

#pragma mark - UITableViewDataSource and UITableViewDelegate
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return 20;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell"];
    if (indexPath.row == 0) {
        cell.separatorInset = UIEdgeInsetsZero;
        cell.textLabel.text = @"系统alert";
    }
    else if (indexPath.row == 1) {
        cell.textLabel.text = @"自定义的LXAlert";
    }
    else if (indexPath.row == 2) {
        cell.textLabel.text = @"RAC的登录注册逻辑的基本用法";
    }
    else if (indexPath.row == 3) {
        cell.textLabel.text = @"TableViewCell类型";
    }
    else if (indexPath.row == 4) {
        cell.textLabel.text = @"系统actionSheet";
    }
    else if (indexPath.row == 8) {
        cell.textLabel.text = @"展示系统图片库";
    }
    else if (indexPath.row == 9) {
        cell.textLabel.text = @"网络测试";
    }
    else if (indexPath.row == 10) {
        cell.textLabel.text = @"日历";
    }
    else if (indexPath.row == 11) {
        cell.textLabel.text = @"设置";
    }
    
    cell.lx_bottomLine.hidden = NO;
    cell.lx_topLine.hidden = YES;
    if (indexPath.row == 0) {
        cell.lx_topLine.hidden = NO;
    }
    
    return cell;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 44;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (indexPath.row == 0) {
        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Welcome" message:@"Hello world" delegate:nil cancelButtonTitle:@"cancel" otherButtonTitles:@"1",@"2", @"3", nil];
        [alert show];
    }
    else if (indexPath.row == 1) {
        [LXAlertView alertWithTitle:@"Welcome" message:@"Hello World!" dismissBlock:^(NSInteger cancelIndex, NSInteger clickIndex) {
            NSLog(@"%ld", clickIndex);
        } cancelTitle:@"cancel" otherButtonTitles:@[@"ok", @"123", @"234"]];
    }
    else if (indexPath.row == 2) {
        UIStoryboard *sb = [UIStoryboard storyboardWithName:@"Main" bundle:[NSBundle mainBundle]];
        UIViewController *vc = [sb instantiateViewControllerWithIdentifier:@"LoginVC"];
        [self.navigationController pushViewController:vc animated:YES];
    }
    else if (indexPath.row == 3) {
        UIStoryboard *sb = [UIStoryboard storyboardWithName:@"Main" bundle:[NSBundle mainBundle]];
        UIViewController *vc = [sb instantiateViewControllerWithIdentifier:@"TableViewController"];
        [self.navigationController pushViewController:vc animated:YES];
    }
    else if (indexPath.row == 4) {
        UIActionSheet *sheet = [[UIActionSheet alloc] initWithTitle:@"Welcome" delegate:nil
                                                  cancelButtonTitle:@"cancel" destructiveButtonTitle:@"OK" otherButtonTitles:@"1", @"2", @"3", nil];
        [sheet showInView:self.view];
    }
    else if (indexPath.row == 5) {
        UIStoryboard *sb = [UIStoryboard storyboardWithName:@"Main" bundle:[NSBundle mainBundle]];
        UIViewController *vc = [sb instantiateViewControllerWithIdentifier:@"SecondVC"];
        [self.navigationController pushViewController:vc animated:YES];
    }
    else if (indexPath.row == 6) {
        [LXAlertManager showActionSheetWithTitle:@"Hello" message:@"World" cancelButtonTitle:@"取消" otherButtonTitles:@[@"1", @"2", @"3", @"4"] inView:self.view dismissBlock:^(NSInteger index, NSInteger cancelIndex) {
            NSLog(@"%ld %ld", index, cancelIndex);
        } presentVC:self];
    }
    else if (indexPath.row == 7) {
        [LXAlertManager showAlertViewWithTitle:@"Title" message:@"This is a message" cancelButtonTitle:@"Cancel" otherButtonTitles:@[@"1", @"2", @"3", @"4"] dismissBlock:^(NSInteger index, NSInteger cancelIndex) {
            NSLog(@"%ld %ld", index, cancelIndex);
        } presentVC:self];
    }
    else if (indexPath.row == 8) {
        AlbumViewController *albumVC = [AlbumViewController new];
        [self.navigationController pushViewController:albumVC animated:YES];
    }
    else if (indexPath.row == 9) {
        NSOperationQueue *queue = [[NSOperationQueue alloc] init];
        NSURL *url = [NSURL URLWithString:@"http://localhost/liu/study.php?id=12"];
        NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url cachePolicy:NSURLRequestReloadIgnoringLocalAndRemoteCacheData timeoutInterval:10];
        request.HTTPMethod = @"POST";
        request.HTTPBody = [@"name=Jack" dataUsingEncoding:NSUTF8StringEncoding];
        LXNetworkOperation *operation = [LXNetworkOperation HTTPRequestOperationWithRequest:request params:nil completionHandler:^{
            
        } failureHandler:^{
            
        }];
        [queue addOperation:operation];
    }
    else if (indexPath.row == 10) {
        CalendarVC *calendarVC = [[CalendarVC alloc] init];
        [self.navigationController pushViewController:calendarVC animated:YES];
    }
    else if (indexPath.row == 11) {
        SettingVC *settingVC = [[SettingVC alloc] init];
        [self.navigationController pushViewController:settingVC animated:YES];
    }
}

@end
